package com.xxxx.server.controller;


import com.xxxx.server.pojo.Admin;
import com.xxxx.server.pojo.RespBean;
import com.xxxx.server.pojo.Role;
import com.xxxx.server.service.IAdminService;
import com.xxxx.server.service.IRoleService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author zhoubin
 */
@Api("操作员管理")
@RestController
@RequestMapping({"/system/admin/", "/system"})
public class AdminController {
    @Autowired
    private IAdminService adminService;
    @Autowired
    private IRoleService iRoleService;
    //根据姓名模糊查询所有操作员
    @ApiOperation(value = "查询操作员")
    @GetMapping("/admin")
    public List<Admin> selectAdminInfo(String keywords){

        return adminService.selectAdminInfo(keywords);
    }

    @GetMapping("/admin/roles")
    @ApiOperation(value ="获得所有角色列表")
    public List<Role> selectAdminRole(){
        return adminService.selectAdminRole();
    }

    @RequestMapping("/admin/{id}")
    @ApiOperation(value="删除操作员")
    public RespBean deleteAdminById (@PathVariable Integer id){
         return adminService.deleteAdminById(id);

    }

    @PutMapping("/admin")
    @ApiOperation("状态的禁用和启用")
    public RespBean updateEnable(@RequestBody Map<String,Object> admin){
        RespBean respBean =adminService.updateEnabledById(admin);
        return  respBean;
    }

    //修改操作员的信息
    @ApiOperation(value = "修改操作员的角色")
    @PutMapping("/admin/role")
    public RespBean updateRoles(Integer adminId, Integer[] rids){
        return adminService.updateRolesById(adminId,rids);
    }
}
